from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-17 14:02:44.724929
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 17, Dec, 2022
Time: 14:02:51
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.2350
Nobs: 873.000 HQIC: -51.5387
Log likelihood: 11520.2 FPE: 3.42995e-23
AIC: -51.7269 Det(Omega_mle): 3.09577e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296213 0.049818 5.946 0.000
L1.Burgenland 0.105279 0.034088 3.088 0.002
L1.Kärnten -0.106776 0.018301 -5.834 0.000
L1.Niederösterreich 0.213911 0.071546 2.990 0.003
L1.Oberösterreich 0.086454 0.067767 1.276 0.202
L1.Salzburg 0.249876 0.036186 6.905 0.000
L1.Steiermark 0.030439 0.047529 0.640 0.522
L1.Tirol 0.127069 0.038726 3.281 0.001
L1.Vorarlberg -0.061782 0.033256 -1.858 0.063
L1.Wien 0.063516 0.060577 1.049 0.294
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064570 0.102431 0.630 0.528
L1.Burgenland -0.010165 0.070088 -0.145 0.885
L1.Kärnten 0.049337 0.037629 1.311 0.190
L1.Niederösterreich -0.174461 0.147106 -1.186 0.236
L1.Oberösterreich 0.362600 0.139335 2.602 0.009
L1.Salzburg 0.286155 0.074402 3.846 0.000
L1.Steiermark 0.108993 0.097724 1.115 0.265
L1.Tirol 0.318244 0.079624 3.997 0.000
L1.Vorarlberg 0.024690 0.068377 0.361 0.718
L1.Wien -0.023959 0.124552 -0.192 0.847
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199777 0.025812 7.740 0.000
L1.Burgenland 0.089763 0.017662 5.082 0.000
L1.Kärnten -0.009071 0.009482 -0.957 0.339
L1.Niederösterreich 0.266523 0.037070 7.190 0.000
L1.Oberösterreich 0.112615 0.035112 3.207 0.001
L1.Salzburg 0.052806 0.018749 2.816 0.005
L1.Steiermark 0.016050 0.024626 0.652 0.515
L1.Tirol 0.101504 0.020065 5.059 0.000
L1.Vorarlberg 0.056803 0.017231 3.297 0.001
L1.Wien 0.114283 0.031386 3.641 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105327 0.026501 3.974 0.000
L1.Burgenland 0.047376 0.018134 2.613 0.009
L1.Kärnten -0.016888 0.009736 -1.735 0.083
L1.Niederösterreich 0.196224 0.038060 5.156 0.000
L1.Oberösterreich 0.277371 0.036049 7.694 0.000
L1.Salzburg 0.117967 0.019250 6.128 0.000
L1.Steiermark 0.100770 0.025284 3.986 0.000
L1.Tirol 0.126102 0.020601 6.121 0.000
L1.Vorarlberg 0.070028 0.017691 3.958 0.000
L1.Wien -0.025062 0.032225 -0.778 0.437
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132166 0.047857 2.762 0.006
L1.Burgenland -0.054330 0.032746 -1.659 0.097
L1.Kärnten -0.036920 0.017581 -2.100 0.036
L1.Niederösterreich 0.165726 0.068730 2.411 0.016
L1.Oberösterreich 0.131107 0.065100 2.014 0.044
L1.Salzburg 0.291120 0.034762 8.375 0.000
L1.Steiermark 0.035019 0.045659 0.767 0.443
L1.Tirol 0.161227 0.037202 4.334 0.000
L1.Vorarlberg 0.108490 0.031947 3.396 0.001
L1.Wien 0.067949 0.058193 1.168 0.243
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060185 0.037899 1.588 0.112
L1.Burgenland 0.038120 0.025933 1.470 0.142
L1.Kärnten 0.049949 0.013923 3.588 0.000
L1.Niederösterreich 0.227046 0.054429 4.171 0.000
L1.Oberösterreich 0.270292 0.051554 5.243 0.000
L1.Salzburg 0.058930 0.027529 2.141 0.032
L1.Steiermark -0.006705 0.036158 -0.185 0.853
L1.Tirol 0.156980 0.029461 5.328 0.000
L1.Vorarlberg 0.069270 0.025300 2.738 0.006
L1.Wien 0.076592 0.046084 1.662 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186415 0.045478 4.099 0.000
L1.Burgenland 0.018347 0.031118 0.590 0.555
L1.Kärnten -0.060305 0.016707 -3.610 0.000
L1.Niederösterreich -0.094433 0.065313 -1.446 0.148
L1.Oberösterreich 0.174157 0.061863 2.815 0.005
L1.Salzburg 0.061133 0.033033 1.851 0.064
L1.Steiermark 0.230308 0.043388 5.308 0.000
L1.Tirol 0.488476 0.035352 13.817 0.000
L1.Vorarlberg 0.051141 0.030358 1.685 0.092
L1.Wien -0.053422 0.055299 -0.966 0.334
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158319 0.051600 3.068 0.002
L1.Burgenland -0.000165 0.035307 -0.005 0.996
L1.Kärnten 0.066467 0.018956 3.506 0.000
L1.Niederösterreich 0.200489 0.074105 2.705 0.007
L1.Oberösterreich -0.070436 0.070191 -1.003 0.316
L1.Salzburg 0.220424 0.037480 5.881 0.000
L1.Steiermark 0.112830 0.049229 2.292 0.022
L1.Tirol 0.083962 0.040111 2.093 0.036
L1.Vorarlberg 0.123684 0.034445 3.591 0.000
L1.Wien 0.106164 0.062743 1.692 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357920 0.030476 11.744 0.000
L1.Burgenland 0.006417 0.020853 0.308 0.758
L1.Kärnten -0.025356 0.011196 -2.265 0.024
L1.Niederösterreich 0.229217 0.043768 5.237 0.000
L1.Oberösterreich 0.156794 0.041456 3.782 0.000
L1.Salzburg 0.052774 0.022137 2.384 0.017
L1.Steiermark -0.016655 0.029076 -0.573 0.567
L1.Tirol 0.121481 0.023691 5.128 0.000
L1.Vorarlberg 0.071333 0.020344 3.506 0.000
L1.Wien 0.047577 0.037058 1.284 0.199
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038744 0.160514 0.182504 0.169386 0.142281 0.128293 0.065689 0.218689
Kärnten 0.038744 1.000000 0.001478 0.132134 0.027178 0.099377 0.432679 -0.049324 0.101172
Niederösterreich 0.160514 0.001478 1.000000 0.346995 0.171152 0.312802 0.128742 0.191736 0.340068
Oberösterreich 0.182504 0.132134 0.346995 1.000000 0.235427 0.342517 0.179551 0.180336 0.272130
Salzburg 0.169386 0.027178 0.171152 0.235427 1.000000 0.153850 0.138664 0.153302 0.139828
Steiermark 0.142281 0.099377 0.312802 0.342517 0.153850 1.000000 0.160286 0.148113 0.093774
Tirol 0.128293 0.432679 0.128742 0.179551 0.138664 0.160286 1.000000 0.123126 0.164559
Vorarlberg 0.065689 -0.049324 0.191736 0.180336 0.153302 0.148113 0.123126 1.000000 0.019109
Wien 0.218689 0.101172 0.340068 0.272130 0.139828 0.093774 0.164559 0.019109 1.000000